<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>添加应用</title>
#include("/sysapp/global_css.html")
<link rel="stylesheet" href="/static/img/ui/sys.css">
</head>

<body>
<div class="alert_addapps">
	#foreach($app in $applist)
		<div class="app" title="$!app.name" appid="$!app.tbid">
		<img src="$!app.icon" alt="$!app.name" title="$!app.name">
		<div class="name">$!app.name</div>
		<span class="selected"></span>
		</div>
	#end
</div>
<input type="hidden" id="value_1">
#include("/sysapp/global_js.html")
<script>
$(function(){
	if($.dialog.data('appsid') != ''){
		$('#value_1').val($.dialog.data('appsid'));
		var appsid = $.dialog.data('appsid').split(',');
		$('.app').each(function(){
			for(var i = 0; i < appsid.length; i++){
				if(appsid[i] == $(this).attr('appid')){
					$(this).addClass('act');
					break;
				}
			}
		});
	}
	$('.app').click(function(){
		if($(this).hasClass('act')){
			var appsid = $('#value_1').val().split(',');
			var newappsid = [];
			for(var i = 0, j = 0; i < appsid.length; i++){
				if(appsid[i] != $(this).attr('appid')){
					newappsid[j] = appsid[i];
					j++;
				}
			}
			$('#value_1').val(newappsid.join(','));
			$(this).removeClass('act');
		}else{
			if($('#value_1').val() != ''){
				var appsid = $('#value_1').val().split(',');
				appsid[appsid.length] = $(this).attr('appid');
				$('#value_1').val(appsid.join(','));
			}else{
				$('#value_1').val($(this).attr('appid'));
			}
			$(this).addClass('act');
		}
		$.dialog.data('appsid', $('#value_1').val());
	});
});
</script>
</body>
</html>